import matplotlib.pyplot as plt
import matplotlib.patches as patches

# 创建一个新的图形
fig, ax = plt.subplots(figsize=(8, 6))

# 画出流程图的各个步骤
steps = [
    ("开始", (0.5, 0.9)),
    ("输入半径", (0.5, 0.75)),
    ("计算周长\nC = 2 * π * radius", (0.5, 0.6)),
    ("计算面积\nArea = π * radius * radius", (0.5, 0.45)),
    ("输出周长和面积", (0.5, 0.3)),
    ("结束", (0.5, 0.15))
]

# 添加矩形框和文本
for step, (x, y) in steps:
    rect = patches.FancyBboxPatch((x - 0.2, y - 0.05), 0.4, 0.1, boxstyle="round,pad=0.1", 
                                    edgecolor='black', facecolor='lightblue')
    ax.add_patch(rect)
    ax.text(x, y, step, ha='center', va='center', fontsize=12, fontweight='bold')

# 添加箭头
for i in range(len(steps) - 1):
    x1, y1 = steps[i][1]
    x2, y2 = steps[i + 1][1]
    ax.annotate("", xy=(x2, y2 + 0.05), xytext=(x1, y1 - 0.05),
                arrowprops=dict(arrowstyle="->", lw=1.5))

# 设置图形的显示属性
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.axis('off')  # 隐藏坐标轴

# 显示流程图
plt.title("圆的面积与周长计算流程图", fontsize=14, fontweight='bold')
plt.show()